#!/usr/bin/env ruby

LKP_SRC = ENV['LKP_SRC'] || File.dirname(File.dirname(File.realpath($PROGRAM_NAME)))

require "#{LKP_SRC}/lib/statistics"

time = []

while (line = gets)
  case line
  when /^Running in .* mode with (\d+) groups using (\d+) file descriptors each \(== (\d+) tasks\)/
    tasks = $3.to_i
  when /^Each sender will pass (\d+) messages of (\d+) bytes/
    messages = $1.to_i
    bytes = $2.to_i
  when /^Each sender passed (\d+) messages of (\d+) bytes in average/
    messages = $1.to_i
    bytes = $2.to_i
  when /^Time:/
    _name, seconds = line.split
    time << seconds.to_f
  end
end

kb = tasks * messages * bytes >> 10
best_time = time.min
puts "throughput: #{kb / best_time}"
